home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST9-5.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  887b  |  39 lines

  1. ;
  2. ; *** Listing 9-5 ***
  3. ;
  4. ; An example of performing a switch statement with just a
  5. ; few cases, all consecutive, by using CMP to test for each
  6. ; of the cases.
  7. ;
  8. ; Macro to perform switch statement. This must be a macro
  9. ; rather than code inside the REPT block because MASM
  10. ; doesn't handle LOCAL declarations properly inside REPT
  11. ; blocks, but it does handle them properly inside macros.
  12. ;
  13. HANDLE_SWITCH    macro
  14.     local    ValueWas1, ValueWas2, ValueWas3, ValueWas4
  15.     cmp    cx,1
  16.     jz    ValueWas1
  17.     cmp    cx,2
  18.     jz    ValueWas2
  19.     cmp    cx,3
  20.     jz    ValueWas3
  21.     cmp    cx,4
  22.     jz    ValueWas4
  23. ;    <none of the above>
  24. ValueWas1:
  25. ValueWas2:
  26. ValueWas3:
  27. ValueWas4:
  28.     endm
  29. ;
  30.     call    ZTimerOn
  31. TEST_VALUE = 1
  32.     rept    1000
  33.     mov    cx,TEST_VALUE    ;set the test value
  34.     HANDLE_SWITCH        ;perform the switch test
  35. TEST_VALUE = (TEST_VALUE MOD 5)+1 ;cycle the test value from
  36.                 ; 1 to 4
  37.     endm
  38.     call    ZTimerOff
  39.